<%--
  Created by IntelliJ IDEA.
  User: 李林
  Date: 2020/4/2
  Time: 22:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--工资管理界面--%>
<%--结算工资 （将待删除月份记录置零 考勤总表 员工福利表 考勤签到表）--%>
<%--修改员工基础工资，职务工资，并结算一次--%>
<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>ERP后台主页</title>
    <meta name="description" content="ERP后台主页">
    <meta name="keywords" content="ERP后台主页">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/morris/morris.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/select2/select2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/pages/plugins/layui/layui.js "></script>
</head>

<body class="hold-transition skin-yellow-light sidebar-mini">

<div class="wrapper">

    <!-- 页面头部 -->
    <jsp:include page="../header.jsp"></jsp:include>
    <!-- 页面头部 /-->

    <!-- 导航侧栏 -->
    <jsp:include page="../aside.jsp"></jsp:include>
    <!-- 导航侧栏 /-->

    <!-- 内容区域 -->
    <div class="content-wrapper onjsp">

        <!-- ========================================== -->
        <section class="content-header">
            <h1>
                工资管理
                <small>Wages</small>
            </h1>
            <ol class="breadcrumb">
                <!-- <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                <li><a href="#">Forms</a></li>
                <li class="active">General Elements</li> -->
            </ol>
        </section>
        <section class="content">
            <div class="col-md-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h2 class="box-title"></h2>
                        <h2 class="box-title" id="box_title">工资结算</h2>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <br>
                    <div class="box-body">
                        <div class="col-md-4">
                            <div class="row" style="margin:30px auto 20px;">
                                <!-- <div class="col-lg-4 col-xs-6"> -->
                                <div>
                                    <!-- small box -->
                                    <div class="small-box bg-yellow">
                                        <div class="inner" style="height: 100px;">
                                            <h3>工资结算</h3>
                                            <p>Wage settlement</p>
                                        </div>
                                        <div id="box_a" class="box small-box-footer collapsed-box" style="border-top: none;">
                                            <a href="#" class="small-box-footer" data-widget="collapse">点击此处</a>
                                            <div class="box-body" style="padding: 5px 10px 5px 10px;">
                                                <div style="margin-bottom: 4px;"><a href="#" onclick="settlement()">结算</a></div>
                                                <div><a href="#" onclick="outexcel()">导出Excel</a></div>
                                            </div>
                                        </div>
                                        <style type="text/css">
                                            #box_a a:hover {
                                                color: black
                                            }

                                            #box_a a:link {
                                                color: rgba(255, 255, 255, 0.8)
                                            }

                                            #box_a a:visited {
                                                color: rgb(255, 255, 255);
                                            }
                                        </style>
                                    </div>
                                </div>
                            </div>
                            <div class="row" style="margin:10px auto 20px;">
                                <!-- <div class="col-lg-4 col-xs-6"> -->
                                <div>
                                    <!-- small box -->
                                    <div class="small-box bg-aqua">
                                        <div class="inner" style="height: 100px;">
                                            <h3>工资查询</h3>
                                            <p>Salary inquiry</p>
                                        </div>
                                        <a href="#" class="small-box-footer" onclick="showWages(1)">点击此处</a>
                                    </div>
                                </div>
                            </div>
                            <div class="row" style="margin:10px auto 20px;">
                                <!-- <div class="col-lg-4 col-xs-6"> -->
                                <div>
                                    <!-- small box -->
                                    <div class="small-box bg-orange">
                                        <div class="inner" style="height: 100px;">
                                            <h3>调整薪资</h3>
                                            <p>Adjust salary</p>
                                        </div>
                                        <a href="#" class="small-box-footer" onclick="showWages(2)">点击此处</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-8" style="height: 600px;">
                            <div id="tax_body" style="padding: 25px 40px 10px 50px;">

                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </section>
        <!-- ========================================== -->


    </div>
    <!-- 内容区域 /-->

    <!-- 底部导航 -->
    <jsp:include page="../foot.jsp"></jsp:include>
    <!-- 底部导航 /-->

</div>


<script src="${pageContext.request.contextPath}/pages/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/raphael/raphael-min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/morris/morris.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/knob/jquery.knob.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/daterangepicker/moment.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/daterangepicker/daterangepicker.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/fastclick/fastclick.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/iCheck/icheck.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/adminLTE/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/treeTable/jquery.treetable.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/select2/select2.full.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/js/markdown.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/js/to-markdown.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/ckeditor/ckeditor.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/input-mask/jquery.inputmask.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/chartjs/Chart.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/flot/jquery.flot.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/flot/jquery.flot.resize.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/flot/jquery.flot.pie.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/flot/jquery.flot.categories.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/ionslider/ion.rangeSlider.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-slider/bootstrap-slider.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/baiduTemplate/baiduTemplate.js"></script>
<script>
    $(document).ready(function() {
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });

    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }

    $(document).ready(function() {
        // 激活导航位置
        setSidebarActive("admin-index");
    });
</script>
</body>
</html>
<script id="per_tax" type="text/template">
    <h2>个人所得税</h2><br>
    <h4>个人所得税率是个人所得税税额与应纳税所得额之间的比例。个人所得税率是由国家相应的法律法规规定的，根据个人的收入计算。 缴纳个人所得税是收入达到缴纳标准的公民应尽的义务。</h4>
    <div id="demo"></div>
</script>
<script id="search_wages" type="text/template">
    <div class="row">
        <div class="col-md-3">
            <select id="wages_sel" name="wagesLevel" class="form-control" style="height: 36px">
                <option value="1">员工ID</option>
                <option value="2">用户名</option>
                <option value="3">姓名</option>
            </select>
        </div>
        <div class="input-group col-md-9">
            <input type="text" id="uid_inp" style="height: 36px;" name="uid_inp" class="form-control search_inp" placeholder="搜索...">
            <span class="input-group-btn">
                  <button type="button" id="wages_btn" onclick="searchWages('<~=sign~>')" style="height: 36px" class="btn btn-flat"><i class="fa fa-search"></i></button>
            </span>
        </div>
    </div>
    <div id="detail_box">
    </div>
</script>
<script type="text/template" id="detail_div">

<div id="p_div" style="margin: 30px auto;">
    <div class="row"><div class="col-md-5"><p>员工ID：</p></div><div class="col-md-7"><span><~=id~></span></div></div>
    <div class="row"><div class="col-md-5"><p>员工姓名：</p></div><div class="col-md-7"><span><~=name~></span></div></div>
    <div class="row"><div class="col-md-5"><p>基本工资：</p></div><div class="col-md-7"><span><~=baseSalary~></span></div></div>
    <div class="row"><div class="col-md-5"><p>工资级别：</p></div><div class="col-md-7"><span><~=wagesLevel~></span></div></div>
    <div class="row"><div class="col-md-5"><p>员工奖金：</p></div><div class="col-md-7"><span><~=welfare~></span></div></div>
    <div class="row"><div class="col-md-5"><p>应发工资：</p></div><div class="col-md-7"><span><~=wagePayable~></span></div></div>
    <div class="row"><div class="col-md-5"><p>实发工资：</p></div><div class="col-md-7"><span><~=wageReal~></span></div></div>
    <div class="row"><div class="col-md-5"><p><a href="#" onclick="detailTanchuang('<~=id~>')">奖金明细：</a></p></div><div class="col-md-7"><span><~=detwelfare~></span></div></div>
</div>
<style>
    #p_div p {
        width: 100%;
        line-height: 25px;
        margin: 10px 10px 15px 10px;
        font-size: 18px;
        text-align: right;
    }
    #p_div div{
        line-height: 25px;
    }
    #p_div span {
        display: block;
        margin: 10px 10px 15px 0px;
        font-size: 18px;
    }
</style>
</script>
<script type="text/template" id="detail_wel_div">
    <div id="d_div" style="margin: 30px auto;">
        <div class="box-body form-horizontal">
            <div class="form-group " style="margin: 10px -15px 40px -15px ;">
                <label for="inputID" class="col-sm-2 control-label">员工ID</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="inputID" name="uid" readonly="readonly" value="<~=id~>">
                </div>
            </div>
            <div class="form-group" style="margin: 10px -15px 40px -15px ;">
                <label for="inputname" class="col-sm-2 control-label">姓名</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="inputname" name="name" readonly="readonly" value="<~=name~>">
                </div>
            </div>
            <div class="form-group" style="margin: 10px -15px 40px -15px ;">
                <label for="inputbaseSalary" class="col-sm-2 control-label">基本工资</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="inputbaseSalary" name="baseSalary" value="<~=baseSalary~>">
                </div>
            </div>
            <div class="form-group" style="margin: 10px -15px 40px -15px ;">
                <label class="col-sm-2 control-label">工资级别</label>
                <div class="col-sm-10">
                    <select name="wagesLevel" class="form-control" id="wages_mod_sel">

                    </select>
                </div>
            </div>
            <div class="box-footer text-center">
                <button type="button" class="btn btn-info " onclick="modifyWages()">修改</button>
            </div>
        </div>
    </div>
</script>
<script>

    $(function () {
        $("#tax_body").html($("#per_tax").html());
        taxtable();
    });

    //发送工资结算命令
    function settlement() {
        $.get("${pageContext.request.contextPath}/admin/wages/settlement",{},function (data) {
            //进入等待界面
            alert(data.message);
        })
    }
    //显示搜索div
    function showWages(sign) {
        if(sign ==1)
            $("#box_title").html("工资查询");
        else $("#box_title").html("调整薪资");
        var bt = baidu.template;
        var html = bt("search_wages",{sign:sign});
        $("#tax_body").html(html);
        // $("#detail_box").html('<table id="search_tab" lay-filter="demo" ></table>')
    }
    //提交修改
    function modifyWages() {
        var uid = $("#inputID").val();
        var baseSalary = $("#inputbaseSalary").val();
        var wagesLevel = $("#wages_mod_sel").val();
        $.post("${pageContext.request.contextPath}/admin/wages/modwages",{uid,baseSalary,wagesLevel},function (data) {
            alert(data.message);
            window.location.href = '../wages';
        })
    }
    //查询要修改的员工
    function searchWages(sign) {
        var flag = $("#wages_sel").val();
        var value = $("#uid_inp").val();
        $("#detail_box").html('<table id="search_tab" lay-filter="demo" ></table>');
        $.get("${pageContext.request.contextPath}/admin/wages/searchone",{flag:flag,value:value},function (data) {
            var pd = [];
            var users = data.resultList["user"];
            // console.log(users);
            for(var i = 0 ; i<users.length;i++){
                if (users[i]!=null){
                    var user = {};
                    user.id = users[i].userInfo.uid;
                    user.name = users[i].userInfo.name;
                    user.baseSalary = users[i].userInfo.baseSalary;
                    user.wagesLevel = users[i].userInfo.wagesLevel;
                    user.welfare = users[i].welfare;
                    user.wagePayable = users[i].wagePayable;
                    user.wageReal = users[i].wageReal;
                    if(sign ==1)
                        user.caozuo = '<input type="button" value="查看" lay-event="detail">';//onclick="detailWages('+users[i].userInfo.uid+')"
                    else user.caozuo = '<input type="button" value="修改" lay-event="edit">';
                    pd.push(user);
                }
            }
            showuserwages(pd);
        })
    }
    
    //展示工资级别
    function showLevel(wagesLevel) {
        $.get("${pageContext.request.contextPath}/admin/wages/wageslevel",{},function (data) {
            var list = data.resultList;
            var levels = list["levels"];
            $("#wages_mod_sel").append('<option value="0">--请选择--</option>');
            for (var i = 0 ; i<levels.length ; i++){
                if(wagesLevel ==levels[i].id ){
                    var option = '<option selected value="'+levels[i].id+'">'+levels[i].level+':'+levels[i].description+'</option>';
                }else
                    var option = '<option value="'+levels[i].id+'">'+levels[i].level+':'+levels[i].description+'</option>';
                $("#wages_mod_sel").append(option);
            }
        })
    }
    function outexcel() {
        $.get("${pageContext.request.contextPath}/admin/wages/outexcel",{},function (data) {
            alert(data.message);
        })
    }

    function taxtable(){
        layui.use('table', function() {
            var table = layui.table;
            //展示已知数据
            table.render({
                elem: '#demo',
                cols: [
                    [ //标题栏
                        {
                            field: 'id',
                            title: '级别',
                            width: 80,
                            sort: true
                        }, {
                        field: 'wages',
                        title: '工资范围',
                        width: 300
                    }, {
                        field: 'free',
                        title: '免征额',
                        minWidth: 100
                    }, {
                        field: 'tax',
                        title: '税率',
                        minWidth: 80
                    }
                    ]
                ],
                data: [{
                    "id": "0",
                    "wages": "1~5000",
                    "free": "5000",
                    "tax": "0"
                }, {
                    "id": "1",
                    "wages": "5001~8000",
                    "free": "5000",
                    "tax": "3%"
                }, {
                    "id": "2",
                    "wages": "8001~17000",
                    "free": "5000",
                    "tax": "10%"
                }, {
                    "id": "3",
                    "wages": "17001~30000",
                    "free": "5000",
                    "tax": "20%"
                }, {
                    "id": "4",
                    "wages": "30001~40000",
                    "free": "5000",
                    "tax": "25%"
                }, {
                    "id": "5",
                    "wages": "40001~60000",
                    "free": "5000",
                    "tax": "30%"
                }, {
                    "id": "6",
                    "wages": "60001~85000",
                    "free": "5000",
                    "tax": "35%"
                }, {
                    "id": "7",
                    "wages": "85001~无限",
                    "free": "5000",
                    "tax": "45%"
                }],
                even: true
            });
        });
    }

    function detailTanchuang(uid) {
        <%--$.get("${pageContext.request.contextPath}/admin/welfare/findwelfare",{uid:uid},function (result) {--%>
            <%--var walfares = result.resultList["userwelfare"];--%>
            <%--if(walfares == null){--%>
                <%--data.detwelfare = "无"--%>
            <%--}--%>
        <%--})--%>
    }

    //该方法获取查询员工的所有奖惩 并展示5个奖惩的名称。
    function detailCaozuo(data,sign) {
        if(sign == 1)
            deatailWelfare(data);
        else{
            console.log(data);
            detailWages(data);
        }

    }

    function deatailWelfare(data) {
        $.get("${pageContext.request.contextPath}/admin/welfare/findwelfare",{uid:data.id},function (result) {
            var walfares = result.resultList["userwelfare"];
            if(walfares == null){
                data.detwelfare = "无"
            }else {
                var detwel = '';
                var length = 5;
                for(var i = 0 ; i<walfares.length&&i<length;i++){
                    if(i+1==walfares.length||i+1==length){
                        detwel += walfares[i].welDesc;
                    }else{
                        detwel += walfares[i].welDesc+' / ';
                    }
                    if(i+1 == length)detwel+='...';
                }
                data.detwelfare = detwel;
            }
            var bt = baidu.template;
            // alert(data);
            var html = bt("detail_div",data);
            // alert(data);
            $("#detail_box").html(html);
        });
    }

    function detailWages(data) {
        var bt = baidu.template;
        var html = bt("detail_wel_div",data);
        $("#detail_box").html(html);
        showLevel(data.wagesLevel);
    }

    function showuserwages(data) {
        layui.use('table', function(){
            var table = layui.table;
            //第一个实例
            table.on('tool(demo)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    detailCaozuo(data,1);
                }else if(obj.event === 'edit'){
                    detailCaozuo(data,2);
                }
            });
            table.render({
                elem: '#search_tab'
                // ,height: 312
                ,page: true //开启分页
                ,cellMinWidth: 70
                ,cols: [[ //表头
                    {field: 'id', title: 'ID', sort: true, fixed: 'left'}
                    ,{field: 'name', title: '姓名'}
                    ,{field: 'baseSalary', title: '基本工资', sort: true}
                    ,{field: 'wagesLevel', title: '工资级别'}
                    ,{field: 'welfare', title: '奖金'}
                    ,{field: 'wagePayable', title: '应发工资', sort: true}
                    ,{field: 'wageReal', title: '实发工资',  sort: true}
                    ,{field: 'caozuo', title: '操作'}
                ]]
                ,data:data
            });

        });
    }
</script>